Skip to content

Sanitize sensitive variables in RequestPanel #2105

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

dr-rompecabezas
Copy link
Member

Description

This pull request enhances the debug_toolbar package by adding functionality to sanitize sensitive data in the Request Panel. It includes changes to the RequestPanel class, utility functions, and tests to ensure sensitive data is properly redacted.

Sanitization of sensitive data:

  • debug_toolbar/panels/request.py: Updated the generate_stats method to use sanitize_and_sort_request_vars for GET, POST, cookies, and session data. [1] [2]
  • debug_toolbar/utils.py: Introduced the sanitize_and_sort_request_vars function to replace get_sorted_request_variable, ensuring sensitive values are redacted. Added helper functions _get_sorted_keys, _process_query_dict, and _process_dict to support sanitization as part of refactoring effort. [1] [2]

Testing enhancements:

  • tests/panels/test_request.py: Added multiple tests to verify that sensitive data in POST, GET, cookies, and session data is redacted.
  • tests/test_utils.py: Added a new test case class SanitizeAndSortRequestVarsTestCase to test the sanitization functionality for different input types.

Documentation update:

  • docs/changes.rst: Documented the new feature to sanitize sensitive data in the Request Panel.

Fixes #2074

Checklist:

  • I have added the relevant tests for this change.
  • I have added an item to the Pending section of docs/changes.rst.

- Refactor sesssion data handling
- Test handling in dicts and QueryDicts
- Test string substitution
- Use helper functions to refactor ugly-looking code
- For consistency with the code
@dr-rompecabezas dr-rompecabezas changed the title Sensitive vars sanitization Sanitize sensitive variables in RequestPanel Mar 13, 2025
Copy link
Member

@matthiask matthiask left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great!

The try-except block in sanitize_and_sort_request_vars was removed as
it was not necessary. The function now directly processes the variable
based on its type and returns the result.
@matthiask matthiask merged commit e6076b5 into django-commons:main Mar 20, 2025
25 checks passed
@dr-rompecabezas dr-rompecabezas deleted the sensitive-vars-sanitization branch March 21, 2025 01:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Sanitize RequestPanel data behind a setting
3 participants